package com.ym521.emojipack.keyboard.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ym521.emojipack.R;
import com.ym521.emojipack.emoji.EmojiPackBean;
import com.ym521.emojipack.keyboard.EmoiiPackClickListener;
import com.ym521.emojipack.keyboard.EmojiPackRecentManager;
import com.ym521.emojipack.keyboard.adapter.EmojiPackGroupAdapter;


/**
 * @author Ym
 */
public final class EmojiPackRecentFragment extends Fragment {
    private EmoiiPackClickListener listener;
    private EmojiPackGroupAdapter emojiPackGroupAdapter;
    public static EmojiPackRecentFragment newInstance() {

        return new EmojiPackRecentFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.emojipack_recent_fragment, container, false);
    }

    public void setEmojiClickedListener(EmoiiPackClickListener listener) {
        this.listener = listener;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        emojiPackGroupAdapter = new EmojiPackGroupAdapter();
        emojiPackGroupAdapter.setListener(listener);
        RecyclerView rlvEmojiPack = view.findViewById(R.id.rlvEmojiPack);
        rlvEmojiPack.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false));
        rlvEmojiPack.setAdapter(emojiPackGroupAdapter);
        rlvEmojiPack.setItemAnimator(null);
    }

    @Override
    public void onResume() {
        super.onResume();
        EmojiPackRecentManager recent = EmojiPackRecentManager
                .getInstance(requireContext());
        emojiPackGroupAdapter.flushData(new EmojiPackBean("最近使用", recent.toEmojiPackArray()),false);
    }
}
